package com.albaba.designpattern.factory.text_003.controller;

import com.albaba.designpattern.factory.text_003.entity.AwardInfo;
import com.albaba.designpattern.factory.text_003.entity.ResponseResult;
import com.albaba.designpattern.factory.text_003.factory.FreeGoodsFactoryMap;
import com.albaba.designpattern.factory.text_003.factory.impl.DiscountFreeGoodsFactory;
import com.albaba.designpattern.factory.text_003.factory.FreeGoodsFactory;
import com.albaba.designpattern.factory.text_003.factory.impl.SmallGiftFreeGoodsFactory;
import com.albaba.designpattern.factory.text_003.service.IFreeGoods;

import java.util.UUID;

/**
 * @Description: 发放奖品
 * @Author zx
 * @Date 2025/2/19 10:46
 * @Version 1.0
 */
public class DeliverController {

    /**
     * 按照类型的不同发放奖品 (奖品类型 1 打折券, 2 优酷会员, 3 小礼品)
     * @param
     */
//    public static ResponseResult awardToUser(AwardInfo awardInfo) {
//
//        FreeGoodsFactory freeGoodsFactory = null;
//
//        switch (awardInfo.getAwardTypes()) {
//            case "1":
//                freeGoodsFactory = new DiscountFreeGoodsFactory();
//                break;
//            case "2":
//                freeGoodsFactory = new SmallGiftFreeGoodsFactory();
//                break;
//            default:
//                break;
//        }
//
//        IFreeGoods iFreeGoods = freeGoodsFactory.getInstance();
//
//        return iFreeGoods.sendFreeGoods(awardInfo);
//    }

    public static ResponseResult awardToUser(AwardInfo awardInfo) {
        // 根据类型获取具体工厂
        FreeGoodsFactory factory = FreeGoodsFactoryMap.getFactory(Integer.parseInt(awardInfo.getAwardTypes()));
        IFreeGoods iFreeGoods = factory.getInstance();
        return iFreeGoods.sendFreeGoods(awardInfo);
    }

    public static void main(String[] args) {

        AwardInfo awardInfo = new AwardInfo();
        awardInfo.setAwardTypes("1");
        awardInfo.setUid(UUID.randomUUID().toString());
        awardInfo.setAwardNumber("MD23532");
        awardToUser(awardInfo);
    }

}
